#事件循环+回调（驱动生成器）+epoll(IO多路复用)
#asyncio是python用于解决异步io编程的一整套解决方案
#tornado、gevent、twisted（scrapy， django channels）
#torando(实现web服务器)， django+flask(uwsgi, gunicorn+nginx)
#tornado可以直接部署， nginx+tornado

# wait和gather
import asyncio
import time
async def get_html(url):
    print("start get url")
    # await time.sleep(2)
    # time.sleep(2)
    await asyncio.sleep(2)
    print("end get url")

if __name__ == '__main__':
    start_time = time.time()

    loop = asyncio.get_event_loop()

    # loop.run_until_complete(get_html("http://www.imooc.com"))
    # tasks = [get_html("http://www.imooc.com") for i in range(10)]
    group1 = [get_html("http://www.imooc.com") for i in range(2)]
    group2 = [get_html("http://www.imooc.com") for i in range(2)]

    # loop.run_until_complete(asyncio.gather(*group1, *group2))
    # 或者
    group1 = asyncio.gather(*group1)
    group2 = asyncio.gather(*group2)
    loop.run_until_complete(asyncio.gather(group1, group2))

    print(time.time() - start_time)


